package cn.qyd.javathread;

/**
 * @author 邱运铎
 * @date 2024-03-14 20:45
 */
public class YuanZiXingSychronizedDemo {
    private static int inc = 0;

    public static synchronized void incrementMethod() {
        inc++;
    }
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread() {
                @Override
                public void run() {
                    for (int i = 0; i < 1000; i++) {
                        incrementMethod();
                    }
                }
            }.start();
        }
        while (Thread.activeCount() > 2) {
            System.out.println(Thread.activeCount());
            Thread.yield();
        }

        System.out.println("add synchronized, inc output: " + inc);

    }

}
